package cn.com.action;

import java.util.Map;

import org.apache.struts2.interceptor.RequestAware;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import cn.com.biz.GuanLiYuanBiz;
import cn.com.biz.UserBiz;
import cn.com.dao.UserDao;
import cn.com.entity.GuanLiYuan;
import cn.com.entity.User;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport implements Action, SessionAware,RequestAware{

	private Map<String,Object> request;
	private Map<String,Object> session;
	private User u;
	private String uname;
	private String upwd;
	
	public String getUname() {
		return uname;
	}

	public void setUname(String uname) {
		this.uname = uname;
	}

	public String getUpwd() {
		return upwd;
	}

	public void setUpwd(String upwd) {
		this.upwd = upwd;
	}

	public User getU() {
		return u;
	}

	public void setU(User u) {
		this.u = u;
	}

	public Map<String, Object> getRequest() {
		return request;
	}

	public Map<String, Object> getSession() {
		return session;
	}

	@Override
	public void setRequest(Map<String, Object> request) {
		// TODO Auto-generated method stub
		this.request=request;
		
	}

	@Override
	public void setSession(Map<String, Object> session) {
		// TODO Auto-generated method stub
		this.session=session;
	}
	
	
	private UserBiz userBiz;
	private GuanLiYuanBiz glyBiz;
	
	
	public GuanLiYuanBiz getGlyBiz() {
		return glyBiz;
	}

	public void setGlyBiz(GuanLiYuanBiz glyBiz) {
		this.glyBiz = glyBiz;
	}

	public UserBiz getUserBiz() {
		return userBiz;
	}

	public void setUserBiz(UserBiz userBiz) {
		this.userBiz = userBiz;
	}
	
	public String execute(){
		ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
		userBiz=(UserBiz)ctx.getBean("userBiz");
		User user=userBiz.login(u);
		if(user!=null){
			session.put("loginUser", user);
			return SUCCESS;
		}else{
			return LOGIN;
		}

	}
	
}
	


